<?php

class Teacher_IndexController extends Zend_Controller_Action
{
    public function init()
    {
        /* Initialize action controller here */
    	defined('BASE_URL')	|| define('BASE_URL', Zend_Controller_Front::getInstance()->getBaseUrl());
    }

    public function indexAction()
    {
    	//Application_Form_FrmMessage::redirector('/userWu/user-type/index');
	}
	public  function profileAction(){
	}
	public  function addTeacherAction(){
		// Show Form Teacher ///////
		$forms = new Teacher_Form_FrmTeacher();
		$frm = $forms->formteacher();
		Application_Model_Decorator::removeAllDecorator($frm);
		$this->view->frmteacher = $frm;
		///////////////////////////////////Select Db of Subject//////////
		$subject= new Application_Model_GlobalClass();
		$subjects = $subject->getSubjectOption();
		$this->view->subjects = $subjects;
		////////// Select Db of Skill//////////
		$skill = $subject->getSkillOption();
		$this->view->skills = $skill;
		/////// Select Db Department ///////////////
		$education = $subject->getEducation();
		$this->view->education = $education;
		
		$frmedu = $forms->addEdu(null);
		Application_Model_Decorator::removeAllDecorator($frmedu);
		$this->view->add_edu = $frmedu;
		//////////Education//////////////////
		$departments = $subject->getDepartmentOption();
		$this->view->department = $departments;
		//////////Form Add Skilll///////////////
		$frmskill = $forms->addskill();
		Application_Model_Decorator::removeAllDecorator($frmskill);
		$this->view->add_frmskill = $frmskill;
		///////////////////////////////
		if($this->getRequest()->isPost()){
			$data = $this->getRequest()->getPost();
			if(isset($data['save_colse'])){
				//print_r($data);
				$db = new Teacher_Model_DbTable_DbTeacher();
				$addteacher = $db->insertTeacher($data);
			}elseif(isset($data['save_new'])){
				//print_r($data);
				$db = new Teacher_Model_DbTable_DbTeacher();
				$addteacher = $db->insertTeacher($data);
			}
		}
	}
	
	public function  listAction(){
		$db = new Teacher_Model_DbTable_DbTeacher();
		$this->_helper->layout()->disableLayout();
		if($this->getRequest()->isPost()){
			$post = $this->getRequest()->getPost();
			if($post["status"] !=""){
				$id = $this->getRequest()->getParam("status");
				if(!empty($id)){
					$db->updateUnStatus ($id);
					$this->_redirect("/teacher/index/list");
				}
			}
			if($post["unstatus"]){
				$id = $this->getRequest()->getParam("unstatus");
				$db->updateStatus($id);
				$this->_redirect("/teacher/index/list");
			}
			if($post["edit"] !=""){
				$id = $this->getRequest()->getParam("chk_modify");
				print_r($id);exit();
				if(!empty($id)){
					$this->_redirect("/teacher/index/edit-teacher/id/".$id);
					$row = $db->geteacher($id);
					$forms = new Teacher_Form_FrmTeacher();
					$frm = $forms->formteacher($row);
					$this->view->frmteacher= $frm;
					///////////////////////////////////Select Db of Subject//////////
					$subject= new Application_Model_GlobalClass();
					$subjects = $subject->getSubjectOption();
					$this->view->subjects = $subjects;
					/////////////////////////////	
					$subject= new Application_Model_GlobalClass();
					$skill = $subject->getSkillOption();
					$this->view->skills = $skill;
					/////// Select Db Department ///////////////
					
					$education = $subject->getEducation();
					$this->view->education = $education;
					
					$row_edu = $subject->getRowEdu($id);
					print_r($row_edu);
					$this->view->rowedu = $row_edu;
					
					$frmedu = $forms->addEdu(null);
					Application_Model_Decorator::removeAllDecorator($frmedu);
					$this->view->add_edu = $frmedu;
					//////////Education//////////////////
					$departments = $subject->getDepartmentOption();
					$this->view->department = $departments;
					//////////Form Add Skilll///////////////
					$frmskill = $forms->addskill();
					Application_Model_Decorator::removeAllDecorator($frmskill);
					$this->view->frmskills = $frmskill;
					////////////////////////////////////
					$subjectedit = $db->geteachersubject($id);
					//print_r($subjectedit);
					$this->view->add_frmsubject = $subjectedit;
					//////////Form  Skilll///////////////
					$frmskill = $db->geteacherskill($id);
					$this->view->add_frmskill = $frmskill;
				}
				else {
					echo "<script type='text/javascript'> alert('Please Try Again'); </script>";
				}
			}
		}
		$data = $db->selectteacher();
		$this->view->formteacher = $data;
	}
	public  function editTeacherAction(){
		$id = $this->getRequest()->getParam("id");
		$db = new Teacher_Model_DbTable_DbTeacher();
		$row = $db->geteacher($id);
		$forms = new Teacher_Form_FrmTeacher();
		$frm = $forms->formteacher($row);
		$this->view->frmteacher= $frm;
		$this->view->photo = $row['photo'];
		///////////////////////////////////Select Db of Subject//////////
		$subject= new Application_Model_GlobalClass();
		$subjects = $subject->getSubjectOption();
		$this->view->subjects = $subjects;
		/////////////////////////////	
		$subject= new Application_Model_GlobalClass();
		$skill = $subject->getSkillOption();
		$this->view->skills = $skill;
		/////// Select Db Department ///////////////
		$departments = $subject->getDepartmentOption();
		$this->view->department = $departments;
		
		
		/////// Select Db Department ///////////////
			
		$education = $subject->getEducation();
		$this->view->education = $education;
			
		$row_edu = $subject->getRowEdu($id);
		print_r($row_edu);
		$this->view->rowedu = $row_edu;
			
		$frmedu = $forms->addEdu(null);
		Application_Model_Decorator::removeAllDecorator($frmedu);
		$this->view->add_edu = $frmedu;
		//////////Education//////////////////
		//////////Form Add Skilll///////////////
		$frmskill = $forms->addskill();
		Application_Model_Decorator::removeAllDecorator($frmskill);
		$this->view->frmskills = $frmskill;
		////////////////////////////////////
		$subjectedit = $db->geteachersubject($id);
		//print_r($subjectedit);
		$this->view->add_frmsubject = $subjectedit;
		//////////Form  Skilll///////////////
		$frmskill = $db->geteacherskill($id);
		$this->view->add_frmskill = $frmskill;
		if($this->getRequest()->isPost()){
			$post = $this->getRequest()->getPost();
			//print_r($post); exit();
			if(isset($post['save_colse'])){
				print_r($post); //exit();
				$db = new Teacher_Model_DbTable_DbTeacher();
				$addteacher = $db->updateTeacher($post);
				$this->_redirect("/teacher/index/list");
			}
						
		}
	}
	public function getDptFilterAction(){
		if($this->getRequest()->isPost()){
			$post=$this->getRequest()->getPost();
			$dpt_id = $post["dpt_id"];	
			$sql = " SELECT	s.subject_id,s.`subject_name` FROM	tbl_subject AS s WHERE dpt_id =".$dpt_id;		
			$db = new Application_Model_DbTable_DbGlobal();
			$row=$db->getGlobalDb($sql);
			echo Zend_Json::encode($row);
			exit();
		}
	}	
	public function addnewskillAction(){
		if($this->getRequest()->isPost()){
			$data = $this->getRequest()->getPost();
			$db = new Teacher_Model_DbTable_DbTeacher();
			if($data != ""){
				$insertskill = $db->addskill($data);
				echo Zend_Json::encode($insertskill);
				exit();
			}else 
			echo Zend_Json::encode($insertskill);
			exit();
		}
	} 
	public function addNewEducationAction(){
		if($this->getRequest()->isPost()){
			$post=$this->getRequest()->getPost();
			$add_new_edu = new Teacher_Model_DbTable_DbTeacher();
			$edu_id = $add_new_edu->addNewEdu($post);
			//print_r($edu_id);
			//$result = array("edu_id"=>$edu_id);
			echo Zend_Json::encode($edu_id);
			exit();
		}
	}
}

